


class HDRItem:
    def __init__(self):
        self.ver = 0
        self.len = 0
        self.flags = 0
        self.cmd = 0
        self.appId = 0
        self.HobByHop = 0
        self.EndToEnd = 0
        self.msg = ""

    def __str__(self):
        from Lib.zcm.dcc.utils import decode_Grouped
        from Lib.zcm.dcc.utils import splitMsgAVPs
        from Lib.zcm.dcc.utils import decodeAVP

        result = ""
        avps = splitMsgAVPs(self.msg)
        for avp in avps:
            result += str(decodeAVP(avp))
        return result

    def get_result(self, dict_avps_code_map, avp_dict_map):
        from Lib.zcm.dcc.utils import splitMsgAVPs
        from Lib.zcm.dcc.utils import decode_avp

        result = []
        avps = splitMsgAVPs(self.msg)
        for avp in avps:
            result.append(decode_avp(avp, dict_avps_code_map))
        result = self.get_dict(result, avp_dict_map)
        return result

    def get_dict(self, value, avp_dict_map):
        c = dict()
        for i in value:
            avp_name = i[0]
            avp_value = i[1]
            if type(avp_value) == list:
                child_c = self.get_dict(avp_value, avp_dict_map)
                if avp_name not in c:
                    c[avp_name] = [child_c]
                else:
                    c[avp_name].append(child_c)
            else:
                # 判断类型是uint，转为int类型
                if avp_name in avp_dict_map:
                    if avp_dict_map[avp_name].type.startswith("Float"):
                        avp_value = int(avp_value)
                c[avp_name] = avp_value
        return c

class AVPItem:
    def __init__(self):
        self.code = 0
        self.name = ""
        self.vendor = 0
        self.type = ""
        self.mandatory = ""
